/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tetris_invader.util;
/**
 * Timer é a classe
     *@param listener recebe o listener
     * @param millis quantos milisegundo ele vai dormir
     *
     */

public class Timer extends Thread {

    public Timer(TimerListener listener, long millis) {
        this.listener = listener;
        this.millis = millis;
        this.pause = false;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(millis);

                if (!pause) {
                    listener.update();
                }
            } catch (InterruptedException ex) {
            }
        }
    }

    public void pause() {
        pause = !pause;
    }

    public boolean isPause(){
        return pause;
    }

    private boolean pause;
    private long millis;
    private TimerListener listener;
}
